<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * @author Anh Nguyen <duyanhnguyen@vccorp.vn>
 * @copyright 2012
 */
class Price_sim extends MX_Controller {

    function __construct() {
        parent::__construct();
        $this->load->library('Admin_Layout');
        $this->load->model('sim/sim_model');
        $this->load->library('pagination');
        $this->load->helper('url');
        $this->load->library('table');
    }

    public function index($page = '') {
        $this->mycommon->authAdmin();
        $data = array();
        $page = ($page != '') ? intval($page) : 1;
        $keyword = $this->input->get('k');
        $numPost = $this->sim_model->count_all($keyword);
        $config['base_url'] = '/admin/price_sim/index';
        $config['total_rows'] = $numPost;
        $config['per_page'] = 10;
        $config['use_page_numbers'] = TRUE;
        $config['first_link'] = '«';
        $config['last_link'] = '»';
        $config['cur_tag_open'] = '<a href="#" class="active">';
        $config['cur_tag_close'] = '</a>';
        $config['num_links'] = '6';
        $config['cur_page'] = $page;
        $config['uri_segment'] = 3;
        $config["suffix"] = ".html?k=.$keyword";
        $this->pagination->initialize($config);
        $start = ($page - 1) * $config['per_page'];
        $data['pagination'] = $this->pagination->create_links();
        $data['headTitle'] = 'Quản lý mua sim';
        $data['current'] = 11;
        $data['keyword'] = $keyword;
        $data['price'] = $this->sim_model->getAllContact($config['per_page'],$start,$keyword);
        $this->admin_layout->render('price_sim/price_sim_view', $data);
    }

    public function getAllContactDetails($id = '') {
        $this->mycommon->authAdmin();
        if ($id == '' && intval($id) != 0) {
            show_404();
        }
        $id = intval($id);
        $data = array();
        $data['headTitle'] = 'Quản lý mua sim';
        $data['current'] = 10;
        $this->load->library('Minifier');
        $data['price'] = $this->sim_model->getAllContactDetails($id);
        $this->admin_layout->render('price_sim/price_sim_details_view', $data);
    }
    
    public function read($id = '')
    {
        $this->mycommon->authAdmin();
        if ($id == '') {
            show_404();
        }
        $id = intval($id);
        $data = array(
            'status' => '2'
        );
        $this->sim_model->updateStatusContact($id, $data);
        redirect('admin/price_sim/index');
    }

}

?>
